package org.example.springchatroom.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.example.springchatroom.model.Message;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 九转苍翎
 * Date: 2025/9/10
 * Time: 22:30
 */
@Mapper
public interface MessageMapper {
    @Select("select content from message where session_id = #{sessionId} order by post_time desc limit 1 offset 0")
    String getLastMessageBySessionId(Integer sessionId);

    @Select("select message_id,from_id,user_name as from_name,session_id,content from message,user where message.from_id = user.user_id and session_id = #{sessionId} order by post_time desc limit 100 offset 0")
    List<Message> getMessageBySessionId(Integer sessionId);

    @Insert("insert into message values (null,#{fromId},#{sessionId},#{content},now())")
    Integer addMessage(Message message);
}
